﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Text.Editor.DragDrop;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Editor;
using FunctionPoint.Common;
using Microsoft.VisualStudio.Utilities;
//using FunctionPoint.UIManagers;
using System.Windows;
using System.Reflection;
using System.Diagnostics;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Shell.Interop;
using FCommon = FunctionPoint.Common;
using Microsoft.VisualStudio.Text.Editor.DragDrop.Implementation;
using FunctionPoint.UIManagers;

//namespace FunctionPoint.Handlers
namespace FunctionPoint
{

    //[DropFormat(FCommon.Constants.DROPHANDLER_SERIALIZABLE)]

    [Export(typeof(IDropHandlerProvider))]

    [DropFormat(FCommon.Constants.DROPHANDLER_TEXT)]
    [DropFormat(FCommon.Constants.DROPHANDLER_CUSTOMDATAFORMAT)]
    [DropFormat(FCommon.Constants.DROPHANDLER_VSPROJECTITEM)]
    [DropFormat(FCommon.Constants.DROPHANDLER_FILEDROP)]
    [DropFormat(FCommon.Constants.DROPHANDLER_WORKITEMTYPE)]
    [DropFormat("VX Clipboard Descriptor Format")]
    [DropFormat("MultiURL")]
    [Name("VSFunctionPointDropHandlerNew")]
    [Order(Before = "DefaultFileDropHandler")]
    public class WorkItemDropHandlerProvider : IDropHandlerProvider, IEditorOperationsFactoryService
    {
        [Import(typeof(IEditorOperationsFactoryService))]
        public IEditorOperationsFactoryService EditorOperationsFactoryService { get; set; }

        [Import(typeof(SVsServiceProvider))]
        private IServiceProvider VsServiceProvider { get; set; }

        public IDropHandler GetAssociatedDropHandler(IWpfTextView wpfTextView)
        {

            IEditorOperations editorOperations = EditorOperationsFactoryService.GetEditorOperations(wpfTextView) as IEditorOperations;

            WpfTextViewAdornmentManager manager = wpfTextView.Properties.GetOrCreateSingletonProperty<WpfTextViewAdornmentManager>(
                () => new WpfTextViewAdornmentManager(wpfTextView, VsServiceProvider));

            return wpfTextView.Properties.GetOrCreateSingletonProperty<WorkItemDropHandler>(
                () => new WorkItemDropHandler(wpfTextView, editorOperations));


        }

        public IEditorOperations GetEditorOperations(ITextView textView)
        {
            IEditorOperationsFactoryService editorOperationsService =
                ServiceProvider.GlobalProvider.GetService(typeof(IEditorOperationsFactoryService)) as IEditorOperationsFactoryService;

            return editorOperationsService.GetEditorOperations(textView);
        }
    }
}
